package it.codelair.activitymanager;

import it.codelair.services.Servizio;
import it.codelair.testcodelair.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.support.v4.app.NavUtils;

public class ActiveServiceMenuActivity extends Activity {
	
	private Servizio service;
	private Intent intent;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_active_service_menu);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_active_service_menu, menu);
        return true;
    }

    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                NavUtils.navigateUpFromSameTask(this);
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
    
    public void toggleButton(View view){
    	ToggleButton button= (ToggleButton)findViewById(R.id.toggleButton1);
    	String message="Le password non corrispondono";
		Context context = getApplicationContext();
		int duration = Toast.LENGTH_SHORT;
    	if(!button.isChecked()){
    		//stoppo il servizio
    		stopService(new Intent(this, Servizio.class));
    		button.setChecked(false);
    		Toast toast = Toast.makeText(context, "Servizio non attivo", duration);
    		toast.show();
    	}
    	else {
    		//attivo il servizio
    		startService(new Intent(this, Servizio.class));
			button.setChecked(true);
    		Toast toast = Toast.makeText(context, "Servizio attivo", duration);
    		toast.show();
    	}
    }

}
